//
//  ZTB_BaseListCell.swift
//  ZYA
//
//  Created by 邱仙凯 on 2024/9/20.
//  Copyright © 2024 zwb. All rights reserved.
//

import UIKit
import Kingfisher
let zbListStatusHeight:CFloat = 19
let zbListStatusWidth:CFloat = 60

class ZTB_BaseListCell: UITableViewCell {
    
   
    lazy var lab1: UILabel = {
        let v = UILabel()
        v.numberOfLines = 2
        v.font = UIFont.boldSystemFont(ofSize: 17)
        
        return v
    }()
    lazy var btnDtradeType: DtradeTypeUIButton = {
        let v = DtradeTypeUIButton()
//        v.isHidden = true
        v.layer.cornerRadius = 14
        v.layer.masksToBounds = true
        v.backgroundColor = #colorLiteral(red: 0.3411764801, green: 0.6235294342, blue: 0.1686274558, alpha: 1)
        v.setTitleColor(.white, for: .normal)
        v.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        return v
    }()
   
    lazy var labCity: UILabel = {
        let v = UILabel()
        v.font = UIFont.systemFont(ofSize: 14)
        v.textColor = .lightGray
        return v
    }()
    
    lazy var lab4: UILabel = {
        
        let lab4 = UILabel()
        lab4.font = UIFont.systemFont(ofSize: 14)
        lab4.textColor = #colorLiteral(red: 0.9254901961, green: 0.3215686275, blue: 0.06274509804, alpha: 1)
        return lab4
    }()
    lazy var chujiaLab: UILabel = {
        let  chujiaLab = UILabel()
        chujiaLab.textColor = .lightGray
        chujiaLab.font = UIFont.systemFont(ofSize: 14)
        chujiaLab.numberOfLines = 2
        return chujiaLab
    }()
    
    lazy  var imageV:UIImageView = {
        let imageV = UIImageView()
        imageV.contentMode = .scaleAspectFit
        imageV.layer.cornerRadius = 8
        imageV.layer.masksToBounds = true
        return imageV
    }()
    
    lazy var chujiaBtn: UIButton = {
        let v = UIButton()
        v.setTitle("出价记录", for: .normal)
        v.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        v.setTitleColor(UIColor(kshex: tenderBlue), for: .normal)
        return v
    }()
    var btn2Closure:((UIButton,String)->())?
    var viewJPClosure:((UIButton,String)->())?
    lazy var titleAttributes:[NSAttributedString.Key : NSObject] = {
        let paraph = NSMutableParagraphStyle()
        //将行间距设置为
        paraph.lineSpacing = 9
        //样式属性集合
        let titleAttributes = [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 17),
                               NSAttributedString.Key.paragraphStyle: paraph]
        return titleAttributes
    }()
    lazy var lab3Attributes:[NSAttributedString.Key : NSObject] = {
        
        
        let paraph2 = NSMutableParagraphStyle()
        //将行间距设置为
        paraph2.lineSpacing = 6
        //样式属性集合
        let  lab3Attributes = [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 14),
                               NSAttributedString.Key.paragraphStyle: paraph2]
        return lab3Attributes
    }()
    let helper = ZyaTenderHelper()
    lazy var bottomStatusBg:BottomStatusV = {
        let v = BottomStatusV()
        return v
    }()
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.selectionStyle = .none
        
        self.contentView.addSubview(lab1)
        
        
        self.contentView.addSubview(labCity)
        
        
        
        
        self.contentView.addSubview(chujiaLab)
        self.contentView.addSubview(chujiaBtn)
        self.contentView.addSubview(lab4)
        
        
        
        self.contentView.addSubview(imageV)
        imageV.addSubview(btnDtradeType)
        self.contentView.addSubview(bottomStatusBg)
      
        
    }
    
    
    
    func makeConstrainsts() {
        
        imageV.snp.makeConstraints { (make) in
            make.left.equalTo(self.contentView).offset(6)
            make.centerY.equalTo(self.contentView)
            make.width.height.equalTo(73)
           
            
        }
     
        btnDtradeType.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(10)
            make.top.equalToSuperview().offset(-10)

             make.width.equalTo(53)
            make.height.equalTo(32)

        }
        lab1.snp.makeConstraints { (make) in
            make.top.equalTo(self.contentView).offset(12)
            make.left.equalTo(imageV.snp.right).offset(8)
            make.right.equalTo(self.contentView).offset(-10)
         
            //                make.bottom.equalTo(self).offset(-100)
        }
      
        labCity.snp.makeConstraints { make in
            make.left.equalTo(lab1)
            make.top.equalTo(lab1.snp.bottom).offset(10)
        }
        
        chujiaLab.snp.makeConstraints { (make) in
            make.centerY.equalTo(bottomStatusBg.statusBtn)
            make.right.equalTo(self.contentView).offset(-10)
        }
        chujiaBtn.snp.makeConstraints { make in
            make.right.equalTo(bottomStatusBg)
            make.width.equalTo(70)
            make.height.equalTo(35)
            make.centerY.equalTo(labCity)
        }
        
        lab4.snp.makeConstraints { (make) in
            make.right.equalTo(bottomStatusBg)
            make.centerY.equalTo(labCity)
            
        }
        bottomStatusBg.snp.makeConstraints { (make) in
            
            make.left.equalTo(lab1)
            make.right.equalTo(self.contentView).offset(-6)
            make.height.equalTo(zbListStatusHeight)
            make.top.equalTo(labCity.snp.bottom).offset(6)
            make.bottom.equalToSuperview().offset(-12)
        }
      
        
    }
    var one = ZtbContentModel(JSON:["":""])! {
        didSet {
            btnDtradeType.setTitle(categoryDicDesc[one.zDtradeType.unwrap].unwrap, for: .normal)

                lab1.text = one.zTitle
                let real_status = one.zStatus.isSome ? intTran(one.zStatus) : intTran(one.zZbStatus)
            let btnName =  bottomStatusBg.statusBtn.setZBJPStatus(listType:.JP,auditmark: intTran(one.zAuditMark), status: real_status,tbType: one.innerType!)
                let ssst = btnName == "未开始" ? "\(one.zBeginDate.unwrap)开始" : "\(one.zEndDate.unwrap)结束"
            bottomStatusBg.lab2.text =  "\(ssst)"
            
            let bcount = intTran(one.zBidCount)
            var cityshow = one.zCity.unwrap
            if bcount > 0 {
                cityshow += " \(bcount)次出价"
            }
                labCity.text = cityshow
                lab4.text = one.zPriceRank.unwrap
                chujiaLab.text = "\(intTran(one.zBidCount))次出价"
                
      
            bottomStatusBg.lab2.endDate = one.zEndDate // 设置10秒后的时间作为目标时间
            if intTran(one.zOvertimedNum) > 0 {
                bottomStatusBg.addtimeLab.isHidden = false

                bottomStatusBg.addtimeLab.text = "加时\(one.zOvertimedNum.unwrap)次"
            } else {
                bottomStatusBg.addtimeLab.isHidden = true

            }
                
                let urlR = configKSURL(one)
                
                if  let imageUrl = URL(string:urlR) {
                    let resource = KF.ImageResource(downloadURL: imageUrl)
                    imageV.kf.setImage(with: resource, placeholder: UIImage(named:"defaultImg"))
                }
                
         
            
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
}
 
